package com.kyle.silverbullet.utils;

/**
 * 用来指示系统中的错误
 */
public enum ResultEnum {
    UNKNOWN_ERROR(0, "未知错误"),
    SUCCESS(20000, "成功"),

    //Register
    AUTHENTICATION_EXCEPTION(1000, "身份验证异常！"),
    REGISTERED_PHONE_NUMBER(1001, "手机号码已被注册，请重新输入号码"),
    INCORRECT_ID_NUMBER(1002, "身份证不正确"),
    REGISTERED_ID_NUMBER(1003, "身份证信息已被注册，请重新输入身份证号码"),
    ACCPEPT_INFO(1004, "信息提交成功，等待管理员审核"),

    //Login
    INCORRECT_PASSWORD(2001, "登陆密码不正确"),
    INVAID_USERNAME(2002, "用户名不正确"),
    ;
    private final Integer code;

    private final String msg;

    ResultEnum(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static String getMsg(Integer code) {
        for (ResultEnum item : ResultEnum.values()) {
            if (item.code.equals(code)) {
                return item.msg;
            }
        }
        return UNKNOWN_ERROR.msg;
    }


    public static String getMsg(String name) {
        for (ResultEnum item : ResultEnum.values()) {
            if (item.name().equals(name)) {
                return item.msg;
            }
        }
        return name;
    }

    public static ResultEnum getEnum(Integer code) {
        for (ResultEnum item : ResultEnum.values()) {
            if (item.code.equals(code)) {
                return item;
            }
        }
        return null;
    }


    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    @Override
    public String toString() {
        return this.name();
    }
}
